/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.ArrayList;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;


/**
 *
 * @author Administrador
 */

@Entity
@Table(name = "attribute")
@NamedQueries({
    @NamedQuery(name = "Attribute.findAll", query = "SELECT a FROM Attribute a"),    
    @NamedQuery(name = "Attribute.findByActiveSubstanceId", query = "SELECT a FROM Attribute a WHERE a.attributePK.activeSubstanceId = :activeSubstanceId"),
    @NamedQuery(name = "Attribute.findByAttributeId", query = "SELECT a FROM Attribute a WHERE a.attributePK.attributeId = :attributeId"),
    @NamedQuery(name = "Attribute.findByAttributeIdMax", query = "SELECT max(a.attributePK.attributeId) FROM Attribute a"),
    @NamedQuery(name = "Attribute.findByAttributeIdByActiveSubstanceId", query = "SELECT a FROM Attribute a WHERE a.attributePK.attributeId = :attributeId AND a.attributePK.activeSubstanceId = :activeSubstanceId"),
    @NamedQuery(name = "Attribute.deleteByActiveSubstanceIdByAttributeId", query = "DELETE FROM Attribute a WHERE a.attributePK.activeSubstanceId = :activeSubstanceId AND a.attributePK.attributeId = :attributeId"),
    @NamedQuery(name = "Attribute.findByName", query = "SELECT a FROM Attribute a WHERE a.name = :name"),
    @NamedQuery(name = "Attribute.findByOrder", query = "SELECT a FROM Attribute a WHERE a.order = :order")})
public class Attribute implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected AttributePK attributePK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Lob
    @Column(name = "detail")
    private String detail;
    @Basic(optional = false)
    @Column(name = "orderAttribute")
    private short order;
    @JoinColumn(name = "activeSubstanceId", referencedColumnName = "activeSubstanceId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Activesubstance activesubstance;

    public Attribute() {
    }

    public Attribute(AttributePK attributePK) {
        this.attributePK = attributePK;
    }

    public Attribute(AttributePK attributePK, String name, String detail, short order) {
        this.attributePK = attributePK;
        this.name = name;
        this.detail = detail;
        this.order = order;
    }
    
    public Attribute( int attributeId, int activeSubstanceId, String name, String detail, short order) {
        this.attributePK = new AttributePK(attributeId, activeSubstanceId);      
        this.name = name;
        this.detail = detail;
        this.order = order;
        //this.country= new Country(countryId);

    }
    

    public Attribute(int attributeId, int activeSubstanceId) {
        this.attributePK = new AttributePK(attributeId, activeSubstanceId);
    }

    public AttributePK getAttributePK() {
        return attributePK;
    }

    public void setAttributePK(AttributePK attributePK) {
        this.attributePK = attributePK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public short getOrder() {
        return order;
    }

    public void setOrder(short order) {
        this.order = order;
    }

    public Activesubstance getActivesubstance() {
        return activesubstance;
    }

    public void setActivesubstance(Activesubstance activesubstance) {
        this.activesubstance = activesubstance;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (attributePK != null ? attributePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Attribute)) {
            return false;
        }
        Attribute other = (Attribute) object;
        if ((this.attributePK == null && other.attributePK != null) || (this.attributePK != null && !this.attributePK.equals(other.attributePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Attribute[ attributePK=" + attributePK + "  ]";
    }
    
}
